import { defineStore } from 'pinia';
import router from '../../router';
import { sessionStorage } from '@/utils/storage';

interface MenuState {
  systemName: String;
  collapsed: Boolean;
  settingsDawer: Boolean;
  activeMenu: Array<string>;
  tagList: Array<any>;
  menuList: Array<any>;
}

export const useMenuStore = defineStore({
  id: 'menu',
  state: (): MenuState => {
    return {
      systemName: 'Vue3-Admin',
      collapsed: false,
      settingsDawer: false,
      activeMenu: sessionStorage.get('activeMenu') || ['/home'],
      tagList: [
        { 
          name: "首页", 
          path: "/home" 
        }
      ],
      menuList: [
        {
          icon: 'icon-branch',
          name: '查询系统',
          children: [
            {
              name: '客户关系管理系统',
              path: '/table'
            },
            {
              name: '综合查询系统',
              // path: '/table'
            },
            {
              name: '影像系统',
              // path: '/table'
            },
            {
              name: '多元信息联系平台',
              // path: '/table'
            },
          ]
        },
        {
          icon: 'icon-branch',
          name: '实操作业',
          children: [
            {
              name: '受理作业',
              // path: '/query'
            },
            {
              name: '客户关系管理系统',
              // path: '/params'
            },
            {
              name: '保单营运系统',
              // path: '/params'
            },
            {
              name: '反洗钱系统',
              // path: '/params'
            },
            {
              name: '智能双录',
              // path: '/params'
            },
            {
              name: '保险销售行为管理系统',
              // path: '/params'
            },
            {
              name: '单证档案系统',
              // path: '/params'
            },
            {
              name: '银行出回盘系统',
              // path: '/params'
            },
            {
              name: '预约服务',
              // path: '/params'
            }
          ]
        },
        {
          icon: 'icon-branch',
          name: '专项追踪',
          children: [
            {
              name: '新契约追踪',
              // path: '/query'
            },
            {
              name: '续期追踪',
              // path: '/params'
            },
            {
              name: '保全退件',
              // path: '/params'
            },
            {
              name: '照会追踪',
              // path: '/params'
            },
            {
              name: '理赔报案追踪',
              // path: '/params'
            },
            {
              name: '理赔撤件',
              // path: '/params'
            }
          ]
        },
        {
          icon: 'icon-branch',
          name: '分派清单作业',
          children: [
            {
              name: '清单导入',
              // path: '/query'
            },
            {
              name: '清单查询',
              // path: '/params'
            },
            {
              name: '清单处理',
              // path: '/params'
            }
          ]
        },
        {
          icon: 'icon-branch',
          name: '知识库',
          children: [
            {
              name: '常用问答',
              // path: '/query'
            },
            {
              name: '高级指南',
              // path: '/params'
            },
            {
              name: '智能知识库',
              // path: '/params'
            }
          ]
        },
        {
          icon: 'icon-branch',
          name: '后台维护',
          children: [
            {
              name: '个人代办',
              // path: '/query'
            },
            {
              name: '保单代办',
              // path: '/params'
            },
            {
              name: '机构信息查询',
              // path: '/params'
            },
            {
              name: '机构调委会信息查询',
              // path: '/params'
            },
            {
              name: '公告栏信息维护',
              // path: '/params'
            }
          ]
        },
      ]
    }
  },
  getters: {},
  actions: {
    // 折叠器
    changeCollapsed(val: boolean) {
      this.collapsed = !this.collapsed;
    },
    // 高亮选中菜单
    changeActiveMenu(val: string) {
      sessionStorage.set('activeMenu', val)
    },
    // 设置面板
    changeSettingDawe(val: boolean) {
      this.settingsDawer = !this.settingsDawer;
    },
    // 新增一个标签
    addTagIten(val: any) {
      if (val.name !== '首页') {
        let result = this.tagList.findIndex(item => item.name === val.name);
        if (result >= 0) {
          return
        } else {
          this.tagList.push(val)
        }
      }
    },
    // 移除一个标签
    removeTagItem(val: any) {
      // 限制了不能删除默认的首页
      for (let i = 0; i < this.tagList.length; i++) {
        if(this.tagList[i].path == val) {
          this.tagList.splice(i, 1)
          router.push({ path: this.tagList[this.tagList.length - 1]['path'] })
        }
      }
    }
  }
})

